package com.woniu.controller;/*
 *
 * @author   米雷
 * @Description 用户服务
 * @Date:create in 13:44 2020-03-24
 *
 * */

import com.woniu.dto.ServerOrderToServer;
import com.woniu.dto.SubscribeToServer;
import com.woniu.pojo.ServerComments;
import com.woniu.pojo.ServerOrders;
import com.woniu.service.OrderService;
import com.woniu.service.PersonService;
import com.woniu.userLog.LogPoint;
import com.woniu.util.CommentResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "服务相关")
@Controller
@RequestMapping(value = "/service")
@CrossOrigin(allowCredentials = "true", maxAge = 3600, origins = "*")
public class ServiceController {

    @Autowired
    PersonService personService;
    @Autowired
    OrderService orderService;

    /*
     * 根据用户id查看用户的服务订单
     * */
    @ApiOperation(value = "查看服务订单")
    @GetMapping("/getServersOrder")
    @ResponseBody
    @LogPoint("用户查看服务订单")
    public List<ServerOrderToServer> getServerOrders(Long id)
    {
        List<ServerOrderToServer> orders = personService.getServerOrders(id);

        return orders;
    }

    /*
     * 根据服务id查询所有服务评论
     *
     * */
    @ApiOperation(value = "查看服务评论")
    @GetMapping("/getServerComments")
    @ResponseBody
    @LogPoint("用户查看服务评论")
    public List<ServerComments> getServiceComments(Long id)
    {
        List<ServerComments> comments = personService.getServiceComment(id);
        return comments;
    }

    /*
     * 查询自己所有服务评论
     *
     * */
    @ApiOperation(value = "查看我的服务评论")
    @GetMapping("/getUserServiceComments")
    @ResponseBody
    @LogPoint("用户查看自己的服务评论")
    public List<ServerComments> getUserServiceComments(Long id)
    {
        List<ServerComments> list = personService.getUserServiceComments(id);
        return list;
    }


    /**
     *
     * 查看自己的预约订单
     */
    @GetMapping("/getSub")
    @ResponseBody
    @ApiOperation(value = "查看我预约的订单")
    @LogPoint("用户查看预约的订单")
    public  List<SubscribeToServer> getMySub(Long id){
        List<SubscribeToServer> list=  orderService.getMySub(id);
        return list;
    }

    /**
     * 取消订单，删除订单表数据，在服务表中增加
     * uid:用户id
     * sid:服务预约id
     * mes，取消原因
     */
    @ApiOperation(value = "取消我预约的订单")
    @PostMapping("/cancel")
    @ResponseBody
    @LogPoint("用户取消预约的订单")
    public String cancelOrder(Long uid, Long sid, String mes)
    {
        String res = orderService.cancelOrder(uid,sid, mes);
        return res;
    }
}
